/**
 * Created with IntelliJ IDEA
 * Description:
 * User: SEKI TOMOKI
 * Date: 2023-09-12
 * Time: 23:48
 */
class Solution {
    public int[] findErrorNums(int[] nums) {
        int[] arr = new int[nums.length];//记录nums中每个数字出现的次数
        int[] ret = new int[2];//要返回的数组
        for(int i = 0; i < nums.length; i++) {
            int index = nums[i] - 1;
            arr[index]++;
        }
        for(int i = 0; i < arr.length; i++) {
            if(arr[i] == 2) {
                ret[0] = i + 1; //nums[i] == index + 1
            }else if(arr[i] == 0) {
                ret[1] = i + 1;
            }
        }
        return ret;
    }
}
